// pages/login/index.js
var config = require('../../utils/config.js')
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  loginBtn(userInfo) {
    wx.showLoading({
      title: '正在登录',
    })
    wx.login({
      success(res){
        console.log("code"+res.code)
        console.log(userInfo.detail.userInfo)
        let user = userInfo.detail.userInfo
        wx.request({
          url: config.HOST+'/user/login',
          data: {
            code: res.code,
            nickName: user.nickName,
            headImg: user.avatarUrl
          },
          header: {
            'content-type': 'application/json' // 默认值
          },
          success(res) {
            console.log(res.data)
            if(res.data.status==200) {
              wx.setStorageSync("token", res.data.data)
              wx.setStorageSync("nickname", user.nickName)
              wx.setStorageSync("headImg", user.avatarUrl)
              wx.hideLoading()
              wx.navigateBack()
            }
          }
        })
      }
    })
    
  }
})